package com.gxa.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.gxa.common.base.RespResult;
import com.gxa.domain.dto.PageDto;
import com.gxa.domain.dto.WarehousePageDto;
import com.gxa.domain.entity.Role;
import com.gxa.domain.entity.User;
import com.gxa.domain.entity.Warehouse;
import com.gxa.service.RoleService;
import com.gxa.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 万事顺意
 * Created with IntelliJ IDEA.
 * User: zwj
 * Date: 2024/07/1814:55
 * Description:
 */
@RestController
@RequestMapping("/warehouse")
public class WarehouseController {
    @Autowired
    private WarehouseService warehouseService;
    @GetMapping("/GetById")
    public RespResult getById(Integer id){
        Warehouse byId= warehouseService.getById(id);
        return RespResult.success(byId);
    }
    @PostMapping("/save")
    public RespResult save(@RequestBody Warehouse warehouse){
        boolean save= warehouseService.save(warehouse);
        if (save){
            return RespResult.success(save);
        }
        return RespResult.error("添加失败");
    }
    @PostMapping("/update")
    public RespResult update(@RequestBody Warehouse warehouse){
        boolean update= warehouseService.updateById(warehouse);
        if (update){
            return RespResult.success(update);
        }
        return RespResult.error("修改失败");
    }
    @PostMapping("/delete")
    public RespResult delete(Integer id) {
        boolean r = warehouseService.removeById(id);
        if (r) {
            return RespResult.success(r);
        }
        return RespResult.error("删除失败");
    }
    @GetMapping("/list")
    public RespResult list(){
        List<Warehouse> list= warehouseService.list();
        return RespResult.success(list);
    }
    @PostMapping("/searchWarehouse")
    public RespResult searchWarehouse(WarehousePageDto dto){
        RespResult searchWarehouse= warehouseService.searchWarehouse(dto);
        return RespResult.success(searchWarehouse);
    }
    @PostMapping("/batchdel")
    public RespResult batchdel(Integer[] ids){
        System.out.println(Arrays.toString(ids));
        boolean r = warehouseService.removeByIds(Lists.newArrayList(ids));
        if (r) {
            return RespResult.success(r);
        }
        return RespResult.error("批量删除失败");
    }



}
